package de.webtech.faceplace.pages;

import java.util.List;

import org.apache.tapestry5.annotations.Persist;
import org.apache.tapestry5.annotations.Property;
import org.apache.tapestry5.hibernate.annotations.CommitAfter;
import org.apache.tapestry5.ioc.annotations.Inject;
import org.apache.tapestry5.services.Request;
import org.hibernate.Session;

import de.webtech.faceplace.entities.Comments;
import de.webtech.faceplace.entities.Messages;
import de.webtech.faceplace.entities.Person;

public class MyPrivateMessages {
	
	@Inject
	private Request request;
    
    @Inject
    private Session session;
	
    public Person getPerson(){
    	Person p = (Person) request.getSession(true).getAttribute("user");
    	
    	for(Object pe : session.createCriteria(Person.class).list()){
    		if(((Person) pe).id.equals(p.id)){
    			return (Person) pe;
    		}
    	}
    	return p;	
    }
	

	@Property
	private Messages currentMessage;
	
	public List<Messages> getMessages() {

		return getPerson().privateMessages;
	}

	public String getPhotoSource() {
		if (getPerson().photoSource != null) {
			return getPerson().photoSource;
		} else {
			return "layout/profilepictures/dummy.jpg";
		}
	}
	
	
	
	
	
	
	

}
